package com.aier.school.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.entity.RequestTeacher;
import com.aier.classes.service.IInviteRequestService;
import com.aier.common.common.Constant;
import com.aier.common.dao.ICommonDAO;
import com.aier.user.service.IUserService;

@Scope("prototype")
@Component("schoolTeacherAuditAction")
public class SchoolTeacherAuditAction extends SchoolBaseAction{

    /**
     * 学校管理-教师审核
     */
    private static final long serialVersionUID = 1L;


    @Resource(name = "inviteRequestService")
    private IInviteRequestService inviteRequestService;    
    @Resource(name = "userService")
    private IUserService userService;    
    
    private int s;                //成功:1 ,失败:0
    private String error_info;    //错误提示信息
        
    private Integer sid;        //学校id
    private List<RequestTeacher> requestTeacherList;    //教师申请记录列表             
    private Long tid;            //教师id
    private Long rtid;            //教师申请记录id
    private Short state;        //审核状态
    
    private int page;            //页数
    private int page_size;        //每页的记录数
    private int page_count;        //总页数
    private int count;            //总数
    
    
    @Override
    public String execute(){
        return SUCCESS;
    }
    
    /**
     * 查询教师申请记录列表
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchRequestTeacherList(){
        s = 0;    
        if (page <= 0) {
            page = 1;
        }
        if (page_size <= 0) {
            page_size = Constant.num_10;
        }
        Map<String,Object> map = inviteRequestService.searchRequestTeacherList(page, 
                page_size, null, sid,(short) 0);
        if(null!=map){
            requestTeacherList = (List<RequestTeacher>) map.get(ICommonDAO.OBJ_LIST);
            if (null != requestTeacherList) {
                for(RequestTeacher rt:requestTeacherList){
                    rt.setUser(userService.getUserByUid(rt.getUid()));
                }
                s = 1;
            }
            page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
            count = (Integer) map.get(ICommonDAO.COUNT);
            page = (Integer) map.get(ICommonDAO.PAGE); 
        }
        return SUCCESS;
    }

    /**
     * 删除教师申请
     */
    public String deleteRequestTeacher(){
        s = inviteRequestService.deleteRequestTeacher(rtid);
        return SUCCESS;
    }
    
    /**
     * 审核教师申请
     */
    public String updateRequestTeacherState(){
        s = inviteRequestService.updateRequestTeacher(rtid, state,tid);
        return SUCCESS;
    }
    
    /**
     * 审核状态
     */
    public String getState(){
        s = inviteRequestService.updateRequestTeacher(rtid, state,tid);
        return SUCCESS;
    }
    
    
    
    
    
    

    public void setPage(int page) {
        this.page = page;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public int getS() {
        return s;
    }

    public String getError_info() {
        return error_info;
    }

    public List<RequestTeacher> getRequestTeacherList() {
        return requestTeacherList;
    }

    public void setInviteRequestService(IInviteRequestService inviteRequestService) {
        this.inviteRequestService = inviteRequestService;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public void setRtid(Long rtid) {
        this.rtid = rtid;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public Integer getSid() {
        return sid;
    }

    public Long getTid() {
        return tid;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public int getPage() {
        return page;
    }

}